package com.storm.model

import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.userdetails.UserDetails

data class JwtUser(
    /**
     * 用户id
     */
    val id: String,
    /**
     * 用户名
     */
    private val username: String,
    /**
     * 密码
     */
    private val password: String,
    /**
     * 权限集合
     */
    private var authorities: Set<GrantedAuthority> = HashSet(),
    /**
     * 可用状态
     */
    private val enabled: Boolean,
    /**
     * 角色集合
     */
    val resources: List<ResourceVO> = ArrayList(),
) : UserDetails {
    fun setAuthorities(set: Set<GrantedAuthority>) {
        authorities = set
    }

    /**
     * 获取权限信息
     */
    override fun getAuthorities(): Set<GrantedAuthority> = authorities

    override fun getPassword(): String = password

    override fun getUsername(): String = username

    /**
     * 是否未过期
     */
    override fun isAccountNonExpired(): Boolean = true

    /**
     * 是否未锁定
     */
    override fun isAccountNonLocked(): Boolean = true

    /**
     * 帐号凭证是否未过期
     */
    override fun isCredentialsNonExpired(): Boolean = true

    /**
     * 是否可用
     */
    override fun isEnabled(): Boolean = true
}

